import router from "./index";
import store from "@/store";

const whiteList = ["/login"];
router.beforeEach((to, from, next) => {
  // console.log(to)
  if (store.getters.token) {
    if (to.matched.length === 0) {
      next("/error");
    } else {
      if (to.path === "/login") {
        // next("/login");
        next();
        localStorage.setItem("token", "");
      } else {
        next();
      }
    }
  } else {
    if (whiteList.includes(to.path)) {
      next();
    } else {
      localStorage.setItem("token", "");
      next("/login");
    }
  }
});


